package com.beiding.workordersystem.orders.generalorder.controller;

import com.beiding.workordersystem.common.standard.R;
import com.beiding.workordersystem.orders.generalorder.service.GeneralOrderService;
import com.beiding.workordersystem.orders.generalorder.service.OrderProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/generalOrder/statistics")
public class StatisticsController {

    @Autowired
    private GeneralOrderService orderService;

    @Autowired
    private OrderProcessService orderProcessService;

    //工单统计
    @GetMapping("/order")
    R order(Date start, Date to) {
        return R.ok(orderService.statistics(start,to));
    }

    //工序统计
    @GetMapping("/process")
    R process(Date start, Date to){
        return R.ok(orderProcessService.statistics(start, to));
    }

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }

}
